# -*- coding: utf_8 -*-
# @Author : RSW
# @Time : 2022/1/8
# @Remark: 机房管理view层


from mxsoftpy import View

from index import _

from utils.public.params_method import check_params

from server.common.CRM.server_room import (GroupServer, SRoomServer, RoomOverviewServer, IOTRelevanceServer,
                                           IOTOperationServer, GroutOverviewServer)

"""机房组操作"""


class AllList(View):
    """展示机房与组"""

    def post(self):
        return GroupServer().all_list()


class AllSearch(View):
    """搜索机房与组"""

    def post(self):
        return GroupServer().all_search(**self.request.POST)


class GroupList(View):
    """展示机房组(添加机房或机房组时使用)"""

    def post(self):
        return GroupServer().list(**self.request.POST)


class GroupAdd(View):
    """添加组"""

    def post(self):
        check_params(self.request.POST, ['group_name'])
        return GroupServer().add(**self.request.POST)


class GroupUpdate(View):
    """编辑组"""

    def post(self):
        check_params(self.request.POST, ['group_code'])
        return GroupServer().update(**self.request.POST)


class GroupDelete(View):
    """删除组(逻辑删除)"""

    def post(self):
        check_params(self.request.POST, ['group_code'])
        return GroupServer().delete(**self.request.POST)


class GroupRetrieve(View):
    """回显机房组"""

    def post(self):
        check_params(self.request.POST, ['sroom_name'])
        return GroupServer().retrieve(**self.request.POST)


class GroupRoute(View):
    """回显机房组路径"""

    def post(self):
        check_params(self.request.POST, ['group_code'])
        return GroupServer().route(**self.request.POST)


"""机房操作"""


class RoomAdd(View):
    """添加机房"""

    def post(self):
        check_params(self.request.POST, ['sroom_name'])
        return SRoomServer().add(**self.request.POST)


class RoomUpdate(View):
    """编辑机房"""

    def post(self):
        check_params(self.request.POST, ['sroom_code'])
        return SRoomServer().update(**self.request.POST)


class RoomDelete(View):
    """删除机房(假删)"""

    def post(self):
        check_params(self.request.POST, ['sroom_code'])
        return SRoomServer().delete(**self.request.POST)


class RoomList(View):
    """机房详情页(点击组时显示)"""

    def post(self):
        check_params(self.request.POST, ['group_parent'])
        return SRoomServer().list(**self.request.POST)


class RoomRetrieve(View):
    """展示指定机房信息(添加机柜时使用,(回显))"""

    def post(self):
        check_params(self.request.POST, ['sroom_code'])
        return SRoomServer().retrieve(**self.request.POST)


class RoomRoute(View):
    """回显机房组路径"""

    def post(self):
        check_params(self.request.POST, ['sroom_code'])
        return SRoomServer().route(**self.request.POST)


class IOTRelevanceView(View):
    """
    动环关联机房
    """

    def post(self):
        check_params(self.request.POST, ['sroom_code', 'device_list'])

        return _("关联成功"), IOTRelevanceServer().update(self.request.POST["sroom_code"], **self.request.POST)


class RoomOverviewList(View):
    """机房概览页面接口"""

    def post(self):
        check_params(self.request.POST, ['sroom_code'])
        return _("查询成功"), RoomOverviewServer().list(self.request.POST['sroom_code'])


class GroupOverviewList(View):
    """机房组概览机柜清单的接口"""

    def post(self):
        check_params(self.request.POST, ['group_parent', "state"])
        return _("查询成功"),GroutOverviewServer().list(**self.request.POST)


class IOTOperationView(View):
    """
    操作动环设备
    """

    def post(self):
        check_params(self.request.POST, ['middle_code', "middle_code", "operation"])

        return _("更新成功"), IOTOperationServer().update(**self.request.POST)
